

/******************************************************************/
/*                    DoFile Replication file
	Review of Economics and Statistics
	
		Victim incentives and criminal activity: 
		Evidence from bus driver robberies in Chile   		  
			
			Author: Patricio Domínguez
			September, 2020										  */

/******************************************************************/

/* Notes: This dofile generates Figure 5 */

set scheme plotplain

/******************************************************************/
/*                    Set directory structure          		      */ 
/******************************************************************/


global rep "/Users/patriciodominguez/RES_Dominguez Dropbox/Patricio Dominguez/Replication/TS"

use "$rep/dta/panel_muni_week.dta", clear

keep if bus==1

collapse (sum) crime, by (cash week)

g pre =0
replace pre=1 if week<42
 
g tra =0
replace tra=1 if week>=42 & week<110
 
g post =0
replace post=1 if week>=110
 
g period =0 if pre
replace period =1 if tra
replace period=2 if post

g pre_cash = pre*cash
g post_cash = post*cash
g tra_cash = tra*cash

g year=2005 if week<52
replace year=2006 if week>=52 &week<104
replace year=2007 if week>=104 &week<156
replace year=2008 if week>=156 &week<208
replace year=2009 if week>=208 &week<260
replace year=2010 if week>=260 
g month = int((week)/52*12)+1 if year ==2005
replace month = int((week-52+1)/52*12)+1 if year ==2006
replace month = int((week-52*2)/52*12)+1 if year ==2007
replace month = int((week-52*3)/52*12)+1 if year ==2008
replace month = int((week-52*4)/52*12)+1 if year ==2009
replace month = int((week-52*5)/52*12)+1 if year ==2010
replace month=12 if month==13

g crime_T=.

forvalues k=0/1 {
	quietly su crime if !tra&!post&cash==`k'
	replace crime_T=crime/`r(mean)' if cash==`k'

}

g ym=ym(year, month)
replace ym = ym-540
tab ym, g(iym)

forvalues i = 1/72 {
    g iymcash`i' = iym`i'*cash
}


set matsize 5000
postfile pdr biv seiv bw using bwrobust, replace

quietly reg crime_T iym2-iym72 iymcash2-iymcash72 cash, r
forvalues i=1/72 { 
	if `i'>0 &`i'<2 {
		post pdr (0) (0) (`i') 
		} 
	else{
		post pdr (_b[iymcash`i']) (_se[iymcash`i']) (`i')
	}
}

postclose pdr
graph drop _all

preserve
use bwrobust, clear
su

gen lbound = biv - 1.96*seiv 
gen ubound = biv + 1.96*seiv

* Figure 5
twoway (rarea lbound ubound bw, col(gs13) msiz(small) ) (line biv bw, lw(vtiny) lp(solid) lc(black)), ///
	yline(0, lcolor(black) lpattern(dash))  xline(10 25, lc(gs8) lp(dash)) legend(off) ///
		ytitle("Estimated Effect", size(med)) xtitle("") name (A) ///
		tlabel(0 "2005" 12 "2006" 24 "2007" 36 "2008" 48 "2009" 60 "2010"  72 "2011", labsize(med) nogrid) xscale(range(0 72) )
		graph export "$rep/Figures/Event_Study_weekly_DD_place_.pdf", replace

restore
